clear;
clc;

cd 'dir'
%%-------------------------------------------------------------------------
%%Part 1: Regressions (Re-weighted)
%%-------------------------------------------------------------------------

%%Plot 1: North American Production Proxy: Treatment
load reg_input.txt

set(0,'DefaultAxesFontSize',12)
na_exp = reg_input(16:29,3)./1000000;
na_exp_se = reg_input(16:29,7)./1000000;
imp_int = reg_input(16:29,4)./1000000;
imp_int_se = reg_input(16:29,8)./1000000;

na_up = na_exp + 1.96*na_exp_se;
na_down = na_exp - 1.96*na_exp_se;
imp_int_up = imp_int + 1.96*imp_int_se;
imp_int_down = imp_int - 1.96*imp_int_se;

time = [-4:1:9]';
zeroline = zeros(length(time),1);

figure(1)
handlevector(1)=plot(time, na_exp,'k','LineWidth',2);
hold on;
handlevector(2)=plot(time,na_up,'k--','LineWidth',1);
handlevector(3)=plot(time,na_down,'k--','LineWidth',1);
handlevector(4)=plot(time,zeroline,'k','LineWidth',1);
grid on;
AX=legend(handlevector([1 2]),...
{'Japanese Firms','95% C.I.'}, 'Location','SouthEast');
LEG = findobj(AX,'type','text');
ylim([-3.5 1])
xlim([-4 9])
set(LEG,'FontSize',12) 
set(gca,'XTick',[-4 -2 0 2 4 6 8 ]);
set(gca,'XTickLabel',[-4 -2 0 2 4 6 8]);
set(gca,'YTick',[-3.5 -3 -2.5 -2 -1.5 -0.5 0 0.5 1]);
set(gca,'YTickLabel',[-3.5 -3 -2.5 -2 -1.5 -0.5 0 0.5 1]);
xlabel('Months Relative to Earthquake');
ylabel('Millions of USD')
print(figure(1), '-dpng','-r600','na_exp_fig.png');

figure(2)
handlevector(1)=plot(time, imp_int,'Color',[0 0 0]+.4,'LineStyle','--','LineWidth',2);
hold on;
handlevector(2)=plot(time,imp_int_up,'Color',[0 0 0]+.4,'LineStyle','--','LineWidth',1);
handlevector(3)=plot(time,imp_int_down,'Color',[0 0 0]+.4,'LineStyle','--','LineWidth',1);
handlevector(4)=plot(time,zeroline,'k','LineWidth',1);
grid on;
AX=legend(handlevector([1 2]),...
{'Japanese Firms','95% C.I.'}, 'Location','SouthEast');
LEG = findobj(AX,'type','text');
xlim([-4 9])
set(LEG,'FontSize',12) 
set(gca,'XTick',[-4 -2 0 2 4 6 8 ]);
set(gca,'XTickLabel',[-4 -2 0 2 4 6 8]);
xlabel('Months Relative to Earthquake');
ylabel('Millions of USD')
print(figure(2), '-dpng','-r600','imp_int_fig.png');




na_exp_perc = na_exp(:,1)./3.50489425;
imp_int_perc = imp_int(:,1)./8.0758935;

figure(3)
handlevector(1)=plot(time, imp_int_perc,'Color',[0 0 0]+.4,'LineStyle','--','LineWidth',2);
hold on;
handlevector(2)=plot(time,na_exp_perc,'k','LineWidth',2);
handlevector(3)=plot(time,zeroline,'k','LineWidth',1);
grid on;
AX=legend(handlevector([1 2]),...
{'Imported Inputs','Output (Proxy)'}, 'Location','SouthEast');
LEG = findobj(AX,'type','text');
xlim([-4 9])
set(LEG,'FontSize',12) 
set(gca,'XTick',[-4 -2 0 2 4 6 8 ]);
set(gca,'XTickLabel',[-4 -2 0 2 4 6 8]);
xlabel('Months Relative to Earthquake');
ylabel('Fraction of Pre-Shock Level')
print(figure(3), '-dpng','-r600','percentage_fig_alt.png');
%print(figure(3),'-depsc2' ,'percentage_fig_alt.eps');
